package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface UserMapper {
    /**
     * 根据openid获取用户
     * @param openId
     * @return
     */
    @Select("select * from user where openid = #{openId}")
    User findByOpenId(String openId);

    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into user values (null, #{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void save(User user);


    @Select("select * from user where id = #{userId}")
    User getById(Long userId);

    Integer countUserStatistics(Map<String, Object> map);

    @Select("select count(*) from user")
    Integer countUser();
}
